<template>
    <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from "echarts";
// import { getUser } from "../../../api/public";
require("echarts/theme/macarons"); // echarts theme
export default {
    props: {
        className: {
            type: String,
            default: "chart",
        },
        width: {
            type: String,
            default: "100%",
        },
        height: {
            type: String,
            default: "350px",
        },
    },
    data() {
        return {
            chart: null,
            data: [],
        };
    },
    mounted() {
        // getUser().then((res) => {
        //     const data = [
        //         { value: res.data.count, name: "用户总数" },
        //         { value: res.data.yes, name: "已激活数" },
        //         { value: res.data.no, name: "未激活数" },
        //         { value: res.data.frozen, name: "已冻结数" },
        //         { value: res.data.delete, name: "已删除数" },
        //         { value: res.data.reject, name: "已驳回数" },
        //     ];
        //     this.$nextTick(() => {
        //         this.initChart(data);
        //     });
        // });
    },
    beforeDestroy() {
        if (!this.chart) {
            return;
        }
        this.chart.dispose();
        this.chart = null;
    },
    methods: {
        initChart(data) {
            this.chart = echarts.init(this.$el, "macarons");

            this.chart.setOption({
                tooltip: {
                    trigger: "item",
                    formatter: "{a} <br/>{b} : {c} ({d}%)",
                },
                legend: {
                    left: "center",
                    bottom: "10",
                    data: [
                        "用户总数",
                        "已激活数",
                        "未激活数",
                        "已冻结数",
                        "已删除数",
                        "已驳回数",
                    ],
                },
                series: [
                    {
                        name: "用户表",
                        type: "pie",
                        roseType: "radius",
                        radius: [15, 95],
                        center: ["50%", "38%"],
                        data: data,
                        animationEasing: "cubicInOut",
                        animationDuration: 2600,
                    },
                ],
            });
        },
    },
};
</script>
